<template>
  <div>
    <el-radio-group v-model="lotteryType" size="large">
      <el-radio-button label="Happy8" value="Happy8" />
      <el-radio-button label="UnionLotto" value="UnionLotto" />
      <el-radio-button label="SuperLotto" value="SuperLotto" />
    </el-radio-group>

    <div class="content">
      <component :is="currentComp"></component>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import Happy8 from '../components/Happy88.vue'
import UnionLotto from '../components/UnionLotto8.vue'
import SuperLotto from '../components/SuperLotto8.vue'
import { getHappy8ListApi, getUnionLottoListApi, getSuperLottoApi } from '../api/index.js'

const lotteryType = ref('Happy8')
const currentComp = computed(() => {
  return {
    Happy8,
    UnionLotto,
    SuperLotto,
  }[lotteryType.value]
})

onMounted(async () => {
  // await getHappy8List()
  // await getUnionLottoList()
  // getSuperLottoList()
})

const getHappy8List = () => {
  getHappy8ListApi({
    name: 'kl8',
    pageNo: 1,
    pageSize: 2000,
    systemType: 'PC',
  })
    .then(({ data: res }) => {
      if (res.state === 0) {
        const list = res?.result?.map((item) => {
          return {
            code: item.code, // 期数
            red: item.red, // 开奖结果
            date: item.date, // 日期
            content: item.content, // 中奖地区
            luckyNumber: item.red.split(','),
          }
        })
        localStorage.setItem('happy8List', JSON.stringify(list))
      } else {
        ElMessage.error('获取数据失败!')
      }
    })
    .catch((error) => {
      console.log('error', error)
    })
    .finally(() => {})
}

const getUnionLottoList = () => {
  getUnionLottoListApi({
    name: 'ssq',
    pageNo: 1,
    pageSize: 2000,
    systemType: 'PC',
  })
    .then(({ data: res }) => {
      if (res.state === 0) {
        const list = res?.result?.map((item) => {
          return {
            code: item.code, // 期数
            red: item.red, // 开奖结果 红
            blue: item.blue, // 开奖结果 蓝
            date: item.date, // 日期
            content: item.content, // 中奖地区
            luckyNumber: `${item.red},${item.blue}`.split(','),
          }
        })
        localStorage.setItem('unionLottoList', JSON.stringify(list))
      } else {
        ElMessage.error('获取数据失败!')
      }
    })
    .catch((error) => {
      console.log('error', error)
    })
    .finally(() => {})
}

const getSuperLottoList = () => {
  getSuperLottoApi({
    gameNo: 85,
    provinceId: 0,
    isVerify: 1,
    pageNo: 1,
    pageSize: 2000,
  })
    .then(({ data: res }) => {
      // return console.log('大乐透', res)
      if (res.success) {
        const list = res?.value?.list?.map((item) => {
          console.log(item.blue?.substr(14, 6))
          return {
            code: item.lotteryDrawNum, // 期数
            red: item.lotteryDrawResult?.substr(0, 14), // 开奖结果 红
            blue: item.lotteryDrawResult?.substr(15, 6), // 开奖结果 蓝
            date: item.lotterySaleEndtime?.substr(0, 10), // 日期
            // content: item.content, // 中奖地区
            luckyNumber: item.lotteryDrawResult.split(' '),
          }
        })
        localStorage.setItem('superLottoList', JSON.stringify(list))
      } else {
        ElMessage.error('获取数据失败!')
      }
    })
    .catch((error) => {
      console.log('error', error)
    })
    .finally(() => {})
}
</script>

<style lang="scss" scoped>
.content {
  margin-top: 18px;
}
</style>
